<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>应用服务管理</title>

		<%@ include file="/commons/css_js_head.jsp"%>
<script type="text/javascript">
//复写Url
doListUrl = "${ctx }/base/appServerAction!doList.ts";
doAddBeforeUrl = "${ctx }/base/appServerAction!doFindById.ts";
doUpdateBeforeUrl = "${ctx }/base/appServerAction!doFindById.ts";
doDelUrl = "${ctx }/base/appServerAction!doDelete.ts"
doSaveMachineUrl = "${ctx }/base/machinesApplyAction!doSaveMachine.ts" 
//添加之前
function doAddBefore() {
	var _form = document.forms[0];
	if (doAddBeforeUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}

	_form.action = doAddBeforeUrl;
	_form.submit();
}

//更新之前 
function doUpdateBefore(pkId) {
	var _form = document.forms[0];
	if (doUpdateBeforeUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}

	_form.action = doUpdateBeforeUrl + "?asId=" + pkId;
	_form.submit();
}

//删除
function doDel(pkId) {
	var _form = document.forms[0];
	if (doDelUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
	_form.action = doDelUrl + "?asId=" + pkId;
	_form.submit();
}
</script>
<script type="text/javascript">
function onCancel()
{
	closeWindow();
}

function closeWindow()
{
	self.parent.tb_remove();
}

//关闭小窗口
function onCancel()
{
	closeWindow();
}
function closeWindow()
{
	self.parent.tb_remove();
}


//全选事件
function selectAll()
{
		var mainChk = document.getElementById("mainChk");
		var addChk = document.getElementsByName("addChk");
		for(var i = 0; i<addChk.length; i++){
			addChk[i].checked = mainChk.checked;
		}
}

//选择要保存的应用的mid
function doSaveMachine(){


	if (doSaveMachineUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
	var nid="";
	var objs = document.getElementsByName("addChk");
	for(var i=0; i<objs.length; i++) {
		if(objs[i].checked==true){
			nid=nid+(objs[i].value)+",";
			
		}	
	}	

	if(nid==""){
	alert("请选择要添加的终端");
	return false;
	}else{
	//alert(nid);
	$.ajax({
              type : "post",
              url : doSaveMachineUrl ,
              cache: false,
              data : "addString=" + nid + "&asid="+asId.value,
              dataType:"json",
              success : function(data){  
              //alert(data);
              if( data== "1" )
               {
                   alert("操作成功");
                   parent.window.location.reload();
                }
               else
               {
                   alert("操作失败");
                   parent.window.location.reload();
               }
              },
              error: function(){alert("服务器没有数据返回，可能服务器忙，请重试");}
           });
	}
	

}

</script>

	</head>
	<body style="overflow-x: hidden">

		<!-- 标题 -->
		<div class="mTitle">
			<span class="hidsearch"><a href="javascript:void(0)"
				onClick="return chg('searchList');" id="ImgArrow"> <img
						src="${ctx}/images/icon_up.gif" id="imgButton" />
			</a> </span>
			<b class="bbig">选择添加信息终端</b>
			
		</div>

		<!--list -->
		<div class="searchBar" id="searchList" style="display: block;">
			<form action="/base/appServerAction!doFindByCompCode" method="post">
				<table class="searchTable">
					<tr>
						<th>
							厂家编码：
						</th>
						<td>
							<s:textfield name="compCode" theme="simple"></s:textfield>
						</td>
						
						
						
						<td>
							<input name="btn_query" type="button" class="btn" value="查询"
								onclick="doQuery()" />
								<input name="btn_save" type="button" class="btn" value="保存"
								onclick="doSaveMachine()" />
							<input name="btn_close" type="button" class="btn" value="关闭"
								onclick="onCancel()" />
							
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div class="mainList">

			<table class="listTable">
				<tr>
					<th><input type="checkbox"  id="mainChk" onclick="javascript:selectAll()"/></th>
					<th>序号</th>
					<th>
						厂家编码
					</th>
					<th>
						设备类型
					</th>
					<th>
						名称
					</th>
					
				</tr>

				
				<input type="hidden" value="${asId}" id="asId"/>
				
				<c:forEach var="machines" varStatus="status" items="${pager.data}">
					<tr align=center>
						<td><input type="checkbox" name="addChk" value="${machines.mid }" id="${machines.mid }"/></td>
						
						<td>${status.index+1} </td>
						<td>
							${machines.compCode}
						</td>
						<td>
							${machines.type}
						</td>
						<td>
							${machines.name}
						</td>
					</tr>
				</c:forEach>
				
			</table>
		</div>
		<!--end list -->

		<!-- 分页区域  -->
<%@ include file="/page/pager.jsp"%>

<script type="text/javascript">
ajaxAnywhere.formName = "form1";
ajaxAnywhere.getZonesToReload = function() {
    return "zoneList";
}
</script>

	</body>
</html>
